/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvc.example.persistence.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author zeta
 */
public abstract class DAOImplJDBC {
    /**
     *Driver de la base de datos MySQL
     */
    public static final String DRIVER = "com.mysql.jdbc.Driver";
    
    private static Connection connection;

    public static Connection getConnection() {
         if(connection == null){
             connection = createConnection();
         }
         return connection;
    }
    
    private static Connection createConnection() {
        Connection con = null;
        try {
            String user = "root";
            String password = "31284081";
            String puerto = "3306";
            String db = "students";
            String host = "localhost";
            String urlConexion = "jdbc:mysql://" + host + ":" + puerto + "/" + db;
            Class.forName(DRIVER);
            con = DriverManager.getConnection(urlConexion,user,password);
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
         return con;
    }
    
}
